﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

namespace Sunboxsoft.ASMS.Client.UI.Common
{
    public static class GridControlUtil
    {
        /// <summary>
        /// 获取grid选中的行，如果选择多行取最先选中的行
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="grid"></param>
        /// <returns></returns>
        public static T GetSelectObject<T>(GridControl grid)
        {
            GridView gridView = grid.MainView as GridView;
            int[] handles = gridView.GetSelectedRows();
            if (handles == null || handles.Length == 0)
            {
                return default(T);
            }
            return (T)gridView.GetRow(handles.First());
        }
    }
}
